<template>
   <div>
       <!--头部  -->
       <mt-header fixed title="传智播客"><mt-button v-if="isshow" @click='backto' icon="back" slot="left">返回</mt-button> </mt-header>
       <!--占位  -->
       <router-view ></router-view>
       <!--底部  -->
       <nav class="mui-bar mui-bar-tab">
        <router-link class="mui-tab-item" to="/home">
				<span class="mui-icon mui-icon-home"></span>
				<span class="mui-tab-label">首页</span>
			</router-link>
        <router-link class="mui-tab-item" to="/tabbar-with-chat">
				<span class="mui-icon mui-icon-contact"></span>
				<span class="mui-tab-label">会员</span>
			</router-link>
        <router-link class="mui-tab-item" to="/shopcar">
                <span class="mui-icon mui-icon-extra mui-icon-extra-cart"><span id="badge" class="mui-badge">0</span></span>
                <!-- <span class="mui-icon-extra mui-icon-extra-cart"></span>    -->
				<span class="mui-tab-label">购物车</span>
			</router-link>
        <router-link class="mui-tab-item" to="/tabbar-with-map">
				<span class="mui-icon mui-icon-search"></span>
				<span class="mui-tab-label">搜索</span>
			</router-link>
      </nav>
   </div>
</template>
<script>
import {getItem,KEY} from './kits/local.js';
import {vm,COUNTSTR} from './kits/vm.js';
var badge=document.getElementById('badge');
console.log(badge);
vm.$on(COUNTSTR,function(input){
    // console.log(input);
    // 追加到购物车
    var badge=document.getElementById('badge');
    // var goods = getItem(KEY)
    // var count=0;
    // goods.forEach(function(element,i) {
    //     count+=parseInt(goods[i].goodscount);
        
    // });
    // console.log(count);
    badge.innerText=parseInt(badge.innerText) + input;
})
    export default{
        
        data(){ //es6语法
            return{
               isshow:false
            }
        },
        watch:{
            '$route':function(newroute,oldroute){
                if(newroute.path.toLowerCase()=='./home'){
                    this.isshow=false;
                }else{
                    this.isshow=true;
                }
            }
        },
        methods:{
            backto(){
                this.$router.go(-1);
            }
            
        },
        created(){

        }
    }
</script>
<style scoped>
</style>
